import { createStore } from 'vuex'

const store = createStore({
    state() {
        return {
            isMobile: false,
            searchPath: '',
            searchKeyword: '',
            authToken: sessionStorage.getItem('token')
        }
    },
    mutations: {
        setIsMobile(state, val) {
            state.isMobile = val
        },
        setSearchPath(state, val) {
            state.searchPath = val
        },
        setSearchKey(state, val) {
            state.searchKeyword = val
        },
        setToken(state, val) {
            state.authToken = val
            sessionStorage.setItem('token', val)
        },
        clearToken(state) {
            state.authToken = ''
            sessionStorage.setItem('token', '')
        }
    },
    actions: {
    },
    modules: {
        file: {
            namespaced: true,
            state() {
                return {
                    selectedFileList: [],
                    isCopy: true,

                    sortKey: 'filename',
                    sortAscend: true,

                    destinationPath: [],

                    isPreviewOpen: false
                }
            },
            mutations: {
                copyFile(state, val) {
                    state.isCopy = true
                    state.selectedFileList = val
                },
                cutFile(state, val) {
                    state.isCopy = false
                    state.selectedFileList = val
                },
                setSortMethod(state, val) {
                    state.sortKey = val
                },
                setSortAscend(state, val) {
                    state.sortAscend = val
                },
                setDestination(state, val) {
                    state.destinationPath = val
                },
                setIsPreviewOpen(state, val) {
                    state.isPreviewOpen = val
                }
            },
        }
    }
})

export default store
